<?php
/**
 * CreateUser:zlh
 * CreateTime:2022/1/15
 * Remark:该类用于对响应方法的返回
 */
namespace App\Func;

use App\Consts\ResponseConsts\ResponseCodeConsts;
use App\Consts\ResponseConsts\ResponseStatusConsts;

class ResponseFunc
{

    private static function gl($permitPath,$request){
        foreach($permitPath as $value){
            if(strstr($request->path(),$value)){
                return true;
            }
        }
        return false;
    }

    /**
     * JSON返回方法
     * @param null $data
     * @param string $msg
     * @param int $code
     * @param string $requestId
     * @return \Illuminate\Http\JsonResponse
     */
    public static function returnJson(string $statusC, mixed $data = null, string $msg = "", int $code = 0, string $requestId = ""): \Illuminate\Http\JsonResponse
    {
        $status   = ResponseStatusConsts::OK_200_RESPONSE_STATUS;
        if($code != ResponseCodeConsts::OK_0_RESPONSE_CODE)
		{
            $status = $code;
        }

		#
		#
        return response()->json	(
									[
										'status'	=> $statusC		,
										'msg'		=> $msg			,
										'code'		=> $code		,
										'data'		=> $data		,

										# this code slice added by breezeer at 2022.05.01
										# 
										# modify bug : 返回的json体缺少 requestId 字段,导致前端数据格式验证失败
										#
										#
										#
										'requestId'	=> $requestId	,
									]
									,
									$status
								)->setEncodingOptions(JSON_UNESCAPED_UNICODE);
    }

}